package com.classichu.jetpacksimple.data.local.dao;

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import com.classichu.jetpacksimple.data.local.entity.ZhihuStory;

import java.util.List;

@Dao
public interface ZhihuStoryDao {
    @Query("SELECT * FROM ZhihuStory WHERE id = :id")
    LiveData<ZhihuStory> query(String id);

    @Query("SELECT * FROM ZhihuStory WHERE title LIKE :titleKeyword ")
    LiveData<List<ZhihuStory>> queryList(String titleKeyword);

    @Query("SELECT * FROM ZhihuStory WHERE id IN (:idList)")
    LiveData<List<ZhihuStory>> queryList(List<String> idList);

    @Query("SELECT * FROM ZhihuStory")
    LiveData<List<ZhihuStory>> queryAll();


    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long insert(ZhihuStory zhihuStory);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long[] insertList(List<ZhihuStory> zhihuStoryList);


    @Update()
    int update(ZhihuStory zhihuStory);

    @Query("UPDATE ZhihuStory SET title = :title  WHERE id = :id")
    int update(String id, String title);

    @Update()
    int updateList(List<ZhihuStory> zhihuStoryList);


    @Delete()
    int delete(ZhihuStory zhihuStory);

    @Query("DELETE  FROM ZhihuStory WHERE id = :id")
    int delete(String id);

    @Query("DELETE  FROM ZhihuStory")
    int deleteAll();

    @Delete()
    int deleteList(List<ZhihuStory> zhihuStoryList);
}
